// package: learn-go
// filename: demo1
// author: diogoxiang@gmail.com
// time: 2023/11/15 10:44
package main

import (
	"fmt"
	"gitee.com/diogoxiang/learn-go/example/lottery_demo/demo1/lottery1"
)

func main() {
	// 设置概率列表
	probabilities := []*lottery1.Probability{
		{
			Name:        "一等奖",
			Probability: 0.1,
			Remaining:   12,
		},
		{
			Name:        "二等奖",
			Probability: 0.2,
			Remaining:   0,
		},
		{
			Name:        "三等奖",
			Probability: 0.7,
			Remaining:   1,
		},
	}

	// 进行 10 次抽奖
	for i := 0; i < 120; i++ {
		index, err := lottery1.Lottery(probabilities)
		if err != nil {
			fmt.Println(err)
			return
		}
		if index == -1 {
			fmt.Println("奖品已抽完  ", i)
		} else {
			// 输出结果
			fmt.Printf("%d 中奖奖品：%s", i, probabilities[index].Name)
			fmt.Println("")
			//fmt.Sprintf("%d 中奖奖品：%s", i, probabilities[index].Name)
		}
	}

}
